<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:constants="http://www.tuanzi.com/constants/tags"
                xmlns:component="http://java.sun.com/jsf/composite/component"
                template="/templates/template.xhtml">
    <ui:define name="title">流程管理</ui:define>
    <ui:define name="content">
        <h:form id="workflowDefinitionListForm">
            <p:defaultCommand target="search"/>
            <div class="topbar clearfix"
                 style="background: -webkit-linear-gradient(top,#f6f7f9 0,#ebedf0 100%);">
                <p:toolbar>
                    <f:facet name="left">
                        <p:commandButton value="批量模式"
                                         icon="fa fa-list-ul"
                                         actionListener="#{workflowDefinitionBean.changeModeToBatch}"
                                         update="@form"
                                         process="@this"
                                         rendered="#{workflowDefinitionBean.isNotBatch()}"/>

                        <p:commandButton value="常规模式" icon="fa fa-file"
                                         actionListener="#{workflowDefinitionBean.changeModeToNormal}"
                                         process="@this"
                                         update="@form"
                                         rendered="#{workflowDefinitionBean.isBatch()}"/>

                        <p:commandButton id="toggler" type="button" value="展示选择"
                                         style="width: auto;"
                                         icon="ui-icon-calculator"/>

                        <p:columnToggler datasource="workflowDataTable" trigger="toggler"/>
                    </f:facet>
                    <f:facet name="right">
                        <p:commandButton id="search" value="查询" icon="fa fa-search"
                                         update="@form"
                                         rendered="#{workflowDefinitionBean.isNormal()}"/>
                        <p:commandButton value="重置" icon="fa fa-refresh"
                                         actionListener="#{workflowDefinitionBean.onReset}"
                                         process="@this"
                                         update="@form"
                                         rendered="#{workflowDefinitionBean.isNormal()}"/>
                        <p:commandButton value="启用" icon="fa fa-play"
                                         actionListener="#{workflowDefinitionBean.onBatchEnable}"
                                         update="@form"
                                         rendered="#{workflowDefinitionBean.isBatch()}"/>
                        <p:commandButton value="禁用" icon="fa fa-warning"
                                         actionListener="#{workflowDefinitionBean.onBatchDisable}"
                                         update="@form"
                                         rendered="#{workflowDefinitionBean.isBatch()}"/>
                        <p:commandButton value="删除" icon="fa fa-remove"
                                         actionListener="#{workflowDefinitionBean.onBatchDelete}"
                                         update="@form"
                                         rendered="#{workflowDefinitionBean.isBatch()}">
                            <p:confirm header="提示信息" message="是否确定删除流程?"
                                       icon="ui-icon-alert"/>
                        </p:commandButton>
                        <p:commandButton value="导入流程" icon="fa fa-upload"
                                         rendered="#{workflowDefinitionBean.isNormal()}"
                                         oncomplete="PF('workflowImportWidgetVar').show()"/>
                    </f:facet>
                </p:toolbar>
            </div>
            <div class="ui-fluid" style="padding-top: 30px;">
                <div class="ui-g">
                    <div class="ui-g-12">
                        <div class="card">
                            <h1>查询条件</h1>
                            <p:panelGrid columns="8" layout="grid"
                                         columnClasses="ui-grid-col-1,ui-grid-col-2"
                                         styleClass="ui-panelgrid-blank"
                                         style="border:0px none; background-color:transparent;">

                                <p:outputLabel for="category" value="流程分类"/>
                                <p:selectOneMenu id="category"
                                                 value="#{workflowDefinitionBean.$.category}"
                                                 filter="true"
                                                 filterMatchMode="contains">
                                    <f:selectItem itemLabel="- 请选择 -" itemValue="" noSelectionOption="true"/>
                                    <f:selectItems
                                            value="#{workflowDefinitionBean.dictionaries[DictionaryCode.WORKFLOW_CATEGORY]}"
                                            var="dic"
                                            itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                                </p:selectOneMenu>

                                <p:outputLabel for="name" value="流程名称"/>
                                <p:inputText id="name" value="#{workflowDefinitionBean.$.name}"/>

                                <p:outputLabel for="code" value="流程编码"/>
                                <p:inputText id="code" value="#{workflowDefinitionBean.$.code}"/>

                                <p:outputLabel for="currentVersion" value="当前版本"/>
                                <p:inputText id="currentVersion"
                                             value="#{workflowDefinitionBean.$.currentVersion}"/>


                            </p:panelGrid>
                        </div>
                        <div class="card">
                            <p:dataTable id="workflowDataTable"
                                         style="width: 100%"
                                         var="workflow"
                                         value="#{workflowDefinitionBean.lazyDataModel}"
                                         rows="#{constants:get('ROWS')}"
                                         lazy="true"
                                         paginator="true"
                                         paginatorTemplate="#{constants:get('PAGINATOR_TEMPLATE')}"
                                         rowsPerPageTemplate="#{constants:get('ROWS_PER_PAGE_TEMPLATE')}"
                                         emptyMessage="#{constants:get('EMPTY_MESSAGE')}"
                                         scrollable="true"
                                         scrollWidth="97%"
                                         reflow="true"
                                         selection="#{workflowDefinitionBean.selectedRecords}"
                                         resizableColumns="true">

                                <p:column headerText="操作" rendered="#{workflowDefinitionBean.isNotBatch()}">
                                    <p:splitButton icon="fa fa-eye"
                                                   oncomplete="PF('workflowImageWidgetVar').show()"
                                                   update=":workflowDefinitionListForm:workflowProcessImageComponent:workflowImageDialog">
                                        <f:setPropertyActionListener value="#{workflow.deploymentId}"
                                                                     target="#{workflowDefinitionBean.deploymentId}"/>
                                        <p:menuitem value="节点管理" icon="fa fa-gears"
                                                    action="#{workflowNodeBean.onLoadNodeData}"
                                                    oncomplete="PF('workflowNodeWidgetVar').show()"
                                                    update=":workflowDefinitionListForm:workflowNodeDialog">
                                            <f:setPropertyActionListener value="#{workflow.id}"
                                                                         target="#{workflowNodeBean.procDefId}"/>
                                        </p:menuitem>
                                        <p:menuitem value="表单管理" icon="fa fa-file-text-o"
                                                    action="#{workflowFormBean.onLoadFormData}"
                                                    oncomplete="PF('workflowFormWidgetVar').show()"
                                                    update=":workflowDefinitionListForm:workflowFormDialog">
                                            <f:setPropertyActionListener value="#{workflow.id}"
                                                                         target="#{workflowFormBean.procDefId}"/>
                                        </p:menuitem>
                                        <p:menuitem value="权限管理" icon="fa fa-sitemap"
                                                    action="#{workflowPermissionBean.onLoadPermissionData}"
                                                    oncomplete="PF('workflowPermissionWidgetVar').show()"
                                                    update=":workflowDefinitionListForm:workflowPermissionDialog">
                                            <f:setPropertyActionListener value="#{workflow.id}"
                                                                         target="#{workflowPermissionBean.procDefId}"/>
                                        </p:menuitem>
                                        <p:menuitem value="审批意见" icon="fa fa-edit"/>
                                        <p:menuitem value="重做脚本" icon="fa fa-file-o"/>
                                        <p:menuitem value="启动页面" icon="fa fa-desktop"
                                                    action="#{workflowStartPageBean.onLoadStartPageData}"
                                                    oncomplete="PF('workflowStartPageWidgetVar').show()"
                                                    update=":workflowDefinitionListForm:workflowStartPageDialog">
                                            <f:setPropertyActionListener value="#{workflow.id}"
                                                                         target="#{workflowStartPageBean.procDefId}"/>
                                        </p:menuitem>
                                        <p:menuitem value="历史版本" icon="fa fa-history"/>
                                        <p:menuitem value="导出流程" icon="fa fa-download"
                                                    actionListener="#{workflowDefinitionBean.onExport(workflow.id)}"
                                                    ajax="false"/>
                                        <p:menuitem value="禁用流程" icon="fa fa-warning"
                                                    actionListener="#{workflowDefinitionBean.onSuspend(workflow.id)}"
                                                    rendered="#{!workflow.suspended}"
                                                    update="@form">
                                            <p:confirm header="提示信息" message="是否确定禁用流程?"
                                                       icon="ui-icon-alert"/>
                                        </p:menuitem>
                                        <p:menuitem value="启用流程" icon="fa fa-play"
                                                    actionListener="#{workflowDefinitionBean.onActive(workflow.id)}"
                                                    rendered="#{workflow.suspended}"
                                                    update="@form">
                                            <p:confirm header="提示信息" message="是否确定启用流程?"
                                                       icon="ui-icon-alert"/>
                                        </p:menuitem>
                                        <p:menuitem value="删除流程" icon="fa fa-remove"
                                                    actionListener="#{workflowDefinitionBean.onDelete(workflow.id)}"
                                                    update="@form">
                                            <p:confirm header="提示信息" message="是否确定删除流程?"
                                                       icon="ui-icon-alert"/>
                                        </p:menuitem>
                                    </p:splitButton>
                                </p:column>

                                <p:column selectionMode="multiple" style="width:16px;text-align:center"
                                          rendered="#{workflowDefinitionBean.isBatch()}"/>

                                <p:column headerText="类型">
                                    <h:outputText
                                            value="#{workflowDefinitionBean.translate(DictionaryCode.WORKFLOW_CATEGORY,workflow.category)}"/>
                                </p:column>
                                <p:column headerText="名称">
                                    <h:outputText value="#{workflow.name}"/>
                                </p:column>
                                <p:column headerText="编码">
                                    <h:outputText value="#{workflow.key}"/>
                                </p:column>
                                <p:column headerText="是否启用">
                                    <h:outputText value="#{workflow.suspended ? '否' : '是'}"/>
                                </p:column>
                                <p:column headerText="部署时间">
                                    <h:outputText value="#{workflow.deploymentTime}">
                                        <f:convertDateTime pattern="#{constants:get('DATETIME_FORMAT')}"/>
                                    </h:outputText>
                                </p:column>
                                <p:column headerText="版本">
                                    <h:outputText value="#{workflow.version}"/>
                                </p:column>
                                <p:column headerText="实例数量">
                                    <h:outputText value="#{workflow.procInstCount}"/>
                                </p:column>
                            </p:dataTable>
                        </div>
                    </div>
                </div>
            </div>


            <component:workflow-process-image id="workflowProcessImageComponent"
                                              deploymentId="#{workflowDefinitionBean.deploymentId}"/>
            <ui:include src="workflow-node-dialog.xhtml"/>
            <ui:include src="workflow-form-dialog.xhtml"/>
            <ui:include src="workflow-permission-dialog.xhtml"/>
            <ui:include src="workflow-start-page-dialog.xhtml"/>
            <ui:include src="workflow-import-dialog.xhtml"/>
        </h:form>
    </ui:define>
</ui:composition>
